<!-- 通知公告 -->
<template>
  <div>
    <!--列表-->
    <el-table size="small" :data="listData" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="width: 100%;">
      <el-table-column align="center" type="selection" width="60">
      </el-table-column>
      <el-table-column sortable center prop="className" label="标题" width="200">
      </el-table-column>
      <el-table-column sortable prop="content" label="内容" width="200">
      </el-table-column>
      <el-table-column  prop="editTime" label="生效时间" width="200">
      </el-table-column>
      <el-table-column sortable prop="classTeacher" label="发布人" width="200">
      </el-table-column>
      <el-table-column sortable prop="addTime" label="发布时间" width="200">
        <template slot-scope="scope">
          <div>{{scope.row.editTime}}</div>
        </template>
      </el-table-column>
      <el-table-column align="center" label="操作" width="300">
        <template slot-scope="scope">
          <el-button size="mini" @click="handlecheck(scope.$index, scope.row)">查看</el-button>
          <el-button size="mini" type="danger" @click="deleteNotice(scope.$index, scope.row)">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    <!-- 分页组件 -->
    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>
   
  </div>
</template>

<script>
import { deptList, deptSave, deptDelete } from '../../api/userMG'
import Pagination from '../../components/Pagination'
export default {
  data() {
    return {
      nshow: true, //switch开启
      fshow: false, //switch关闭
      loading: false, //是显示加载
      editFormVisible: false, //控制编辑页面显示与隐藏
      title: '添加',
      editForm: {
        classID: '',
       className: '',
       classNo: '',
        token: localStorage.getItem('logintoken')
      },
      formInline: {
        page: 1,
        limit: 10,
        varLable: '',
        varName: '',
        token: localStorage.getItem('logintoken')
      },
      // 删除部门
      seletedata: {
        ids: '',
        token: localStorage.getItem('logintoken')
      },
      userparm: [], //搜索权限
      listData: [], //用户数据
      // 分页参数
      pageparm: {
        currentPage: 1,
        pageSize: 10,
        total: 10
      }
    }
  },
  // 注册组件
  components: {
    Pagination
  },
  created() {
    this.getdata(this.formInline)
  },

 
  methods: {
    getdata(parameter) {
      this.loading = true
      // 模拟数据开始
      let res = {
        code: 0,
        msg: null,
        count: 3,
        data: [
          {

            addTime: "2024年1月1日",
            editTime:'2024年1月1日',
            classID: 2,
            className: '元旦放假通知',
            classNo: 'V001',
            content:'元旦放假通知',
            classTeacher: '王琳',
            classPeople: 7,
            parentId: 1
          },
          {
            addTime: "2024年3月1日",
            editTime:'2024年3月1日',
            classID: 3,
           className: 'vue公开课通知',
           classNo: 'J002',
           content:'vue公开课通知',
           classTeacher: '初夏',
           classPeople: 10,
            parentId: 1
          },
          {
            addTime: "2024年4月1日",
            editTime:'2024年4月4日',
            classID: 12,
           className: '清明节放假通知',
           classNo: 'J003',
           classTeacher: '刘梦',
           classPeople: 6,
           content:'清明节放假通知',
            parentId: 1
          },
         
        ]
      }
      this.loading = false
      this.listData = res.data
      this.pageparm.currentPage = this.formInline.page
      this.pageparm.pageSize = this.formInline.limit
      this.pageparm.total = res.count
      // 测试环境  模拟数据结束  
    },
    // 分页插件事件
    callFather(parm) {
      this.formInline.page = parm.currentPage
      this.formInline.limit = parm.pageSize
      this.getdata(this.formInline)
    },
    // 搜索事件
    search() {
      this.getdata(this.formInline)
    },
    //显示查看界面
    handlecheck: function(index, row) {
      this.editFormVisible = true
    },
    // 删除评论
    deleteNotice(index, row) {
      this.$confirm(`确定要删除《${row.className}》评论吗?`, '删除评论', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      })
        .then(() => {
          deptDelete(row.classID)
            .then(res => {
              if (res.success) {
                this.$message({
                  type: 'success',
                  message: '评论已删除!'
                })
                this.getdata(this.formInline)
              } else {
                this.$message({
                  type: 'info',
                  message: res.msg
                })
              }
            })
            .catch(err => {
              this.loading = false
              this.$message.error('评论删除失败，请稍后再试！')
            })
        })
        .catch(() => {
          this.$message({
            type: 'info',
            message: '已取消删除'
          })
        })
    },
    // 关闭编辑、增加弹出框
    closeDialog() {
      this.editFormVisible = false
    }
  }
}
</script>

<style scoped>
.user-search {
  margin-top: 20px;
}
.userRole {
  width: 100%;
}
</style>

 
 